home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
choice.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
1KB
|
82 lines
/************************************************************************
* $Id: choice.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
*
*. Copyright(c) 1993,1994 by T.C. Zhao
* All rights reserved.
*.
* Routines used to parse options.
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_choice = "$Id: choice.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
#endif
#include <string.h>
#include "ulib.h"
static int sep = '|';
static char ssep[2];
void
set_sep_letter(int c)
{
ssep[0] = sep = c;
}
int
sep_choices(char *choices, char *obuf[])
{
register char *c = choices;
register int n = 0;
register char *entry = obuf[0];
ssep[0] = sep;
while (*c)
{
if (*c != sep)
{
if (*c != '\n')
*entry++ = *c;
}
else
{
*entry = '\0';
entry = obuf[++n];
}
c++;
}
*entry = '\0';
return ++n;
}
const char *
comb_choices(char *inbuf[], int n)
{
static char localstr[1024];
int i;
ssep[0] = sep;
strcpy(localstr, inbuf[0]);
for (i = 1; i < n && inbuf[i]; i++)
strcat(strcat(localstr, ssep), inbuf[i]);
return localstr;
}
#ifdef TEST
#include <stdio.h>
main()
{
char ll[1024], pool[100][20];
char *p[100];
int i, k;
for (i = 0; i < 100; i++)
p[i] = pool[i];
while (fgets(ll, 1024, stdin))
{
printf("total %d\n", k = sep_choices(ll, p));
printf("%s\n", comb_choices(p, k));
}
}
#endif